package com.maozzi.web.controller.rest;

import com.maozzi.api.user.UserService;
import com.maozzi.api.user.model.UserDTO;
import com.maozzi.common.util.CloneUtil;
import com.maozzi.common.util.ParamCheckUtil;
import com.maozzi.web.model.UserVO;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册controller
 *
 * @author maozi
 */
@RestController
@RequestMapping("/rest")
public class SignupController {
    @Resource
    private UserService userService;

    private final static String AVATAR = "https://maozzi.gitlab.io/images/avatar.gif";

    @PostMapping("signup.json")
    public Boolean signup(@RequestBody UserVO vo) {
        ParamCheckUtil.notNull(vo, "参数错误");
        ParamCheckUtil.notBlank(vo.getName(), "名称为空");
        ParamCheckUtil.notBlank(vo.getPassword(), "密码为空");

        vo.setAvatar(AVATAR);

        UserDTO dto = CloneUtil.to(vo, UserDTO.class);
        return userService.signup(dto);
    }

}
